#ifndef __OS_SYNC__
#define __OS_SYNC__

namespace mm
{
	struct mutex_t
	{
		CRITICAL_SECTION _cs;
		mutex_t()
		{
			::InitializeCriticalSection( &_cs );
		}
		~mutex_t()
		{
			::DeleteCriticalSection( &_cs );
		}
		void enter()
		{
			::EnterCriticalSection( &_cs );
			//printf( "[%d] %d enter\n", ::GetCurrentThreadId(), clock() );
		}
		void leave()
		{
			::LeaveCriticalSection( &_cs );
			//printf( "[%d] leave\n", ::GetCurrentThreadId() );
		}
	};

	struct sync_t
	{
		mutex_t & _mutex_;
		sync_t( mutex_t & rm )
			: _mutex_( rm )
		{
			_mutex_.enter();
		}
		~sync_t()
		{
			_mutex_.leave();
		}
	};

};

#endif